/**
 * @author tian qingsen
 */
$(function() {
	// 宣传图片一
	var uploadBtn = $('#uploadBtn'), interval1;
	new AjaxUpload(uploadBtn, {
		action : window.ctx + '/admin/upload/logo_process.htm',
		name : 'fileInput',
		filetype : 'image/*',
		onChange: function(file, ext) {
			if (! (ext && /^(jpg|png|jpeg|bmp|gif)$/.test(ext))){
				// 扩展名不允许
				$('#up_bk_msg').text('不支持的图片类型，请重新选择');
				return false;
			}
		},
		onSubmit : function(file, ext) {
			$('#up_bk_msg').text('上传中');
			uploadBtn.prop('disabled', true);
	
			// 上传中 -> 上传中. -> 上传中...
			interval1 = window.setInterval(function() {
				var text = $('#up_bk_msg').text();
				if (text.length < 6) {
					$('#up_bk_msg').text(text + '.')
				} else {
					$('#up_bk_msg').text('上传中')
				}
			}, 200);
		},
		onComplete : function(file, response) {
			if (BooleanHelper.isTrue(response.successful)) {
				setImgPath('logo_img', response.message);
				$('#up_bk_msg').text('');
			} else {
				$('#up_bk_msg').text(response.message);
			}
			uploadBtn.prop('disabled', false);
			window.clearInterval(interval1);
		}
	});
});

//上传图片成功后设置图片路劲
function setImgPath(imgId, path) {
	var imgsrc = window.ctx + path + '?'+ Math.floor(Math.random() * 100);
	$('#' + imgId).attr('src', imgsrc);
}
